﻿using FwDl.Common;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace BindCodes
{
    public partial class FrmExp : Form
    {
        int steps = 0;
        public List<string> codes { get; set; }
        public int Opr { get; set; }
        public FrmExp()
        {
            InitializeComponent();
        }

        private void FrmExp_Load(object sender, EventArgs e)
        {
            codes = new List<string>();
            lstOpr.SelectedIndex = 0;
        }

        private void lstOpr_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch (lstOpr.SelectedIndex)
            {
                case 0:
                    txtLog.Text = "扫描/输入瓶盖码或者追溯码来删除"; 
                    steps=0;
                    codes.Clear();
                    break;

                case 1:
                    txtLog.Text = "先扫瓶盖码，再扫描追溯码"; 
                    steps = 0;
                    codes.Clear();
                    break;
                default:
                    break;
            }

        }

        public void AppendCode(string code)
        {
            if (steps == 0)
            {
                CallCtrlWithThreadSafety.SetEnable(lstOpr, false, this);
                CallCtrlWithThreadSafety.SetEnable(btnOK, true, this);

                steps++;
            }

            CallCtrlWithThreadSafety.AppendText(txtLog, "扫描条码：" + code + "\r\n", this);
            codes.Add(code.Trim());

            CallCtrlWithThreadSafety.SetText(lbQty, "条码数量：" + codes.Count, this);
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            Opr = lstOpr.SelectedIndex;
            this.DialogResult = DialogResult.OK;
            Close();
        }

        private void txtCodeInput_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                if (txtCodeInput.Text.Trim().Length!=0)
                {
                    AppendCode(txtCodeInput.Text);
                }
                
            }
        }
    }
}
